


<!DOCTYPE html>
<html id="htmlId">
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
  <title>Coverage Report > BoardPanel</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.ui</a>
</div>

<h1>Coverage Summary for Class: BoardPanel (nl.tudelft.jpacman.ui)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">BoardPanel</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/27)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.ui;
&nbsp;
&nbsp;import java.awt.Color;
&nbsp;import java.awt.Dimension;
&nbsp;import java.awt.Graphics;
&nbsp;
&nbsp;import javax.swing.JPanel;
&nbsp;
&nbsp;import nl.tudelft.jpacman.board.Board;
&nbsp;import nl.tudelft.jpacman.board.Square;
&nbsp;import nl.tudelft.jpacman.board.Unit;
&nbsp;import nl.tudelft.jpacman.game.Game;
&nbsp;
&nbsp;/**
&nbsp; * Panel displaying a game.
&nbsp; *
&nbsp; * @author Jeroen Roosen 
&nbsp; *
&nbsp; */
<b class="nc">&nbsp;class BoardPanel extends JPanel {</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Default serialisation ID.
&nbsp;     */
&nbsp;    private static final long serialVersionUID = 1L;
&nbsp;
&nbsp;    /**
&nbsp;     * The background colour of the board.
&nbsp;     */
<b class="nc">&nbsp;    private static final Color BACKGROUND_COLOR = Color.BLACK;</b>
&nbsp;
&nbsp;    /**
&nbsp;     * The size (in pixels) of a square on the board. The initial size of this
&nbsp;     * panel will scale to fit a board with square of this size.
&nbsp;     */
&nbsp;    private static final int SQUARE_SIZE = 16;
&nbsp;
&nbsp;    /**
&nbsp;     * The game to display.
&nbsp;     */
&nbsp;    private final Game game;
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new board panel that will display the provided game.
&nbsp;     *
&nbsp;     * @param game
&nbsp;     *            The game to display.
&nbsp;     */
&nbsp;    BoardPanel(Game game) {
<b class="nc">&nbsp;        super();</b>
<b class="nc">&nbsp;        assert game != null;</b>
<b class="nc">&nbsp;        this.game = game;</b>
&nbsp;
<b class="nc">&nbsp;        Board board = game.getLevel().getBoard();</b>
&nbsp;
<b class="nc">&nbsp;        int w = board.getWidth() * SQUARE_SIZE;</b>
<b class="nc">&nbsp;        int h = board.getHeight() * SQUARE_SIZE;</b>
&nbsp;
<b class="nc">&nbsp;        Dimension size = new Dimension(w, h);</b>
<b class="nc">&nbsp;        setMinimumSize(size);</b>
<b class="nc">&nbsp;        setPreferredSize(size);</b>
&nbsp;    }
&nbsp;
&nbsp;    @Override
&nbsp;    public void paint(Graphics g) {
<b class="nc">&nbsp;        assert g != null;</b>
<b class="nc">&nbsp;        render(game.getLevel().getBoard(), g, getSize());</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Renders the board on the given graphics context to the given dimensions.
&nbsp;     *
&nbsp;     * @param board
&nbsp;     *            The board to render.
&nbsp;     * @param graphics
&nbsp;     *            The graphics context to draw on.
&nbsp;     * @param window
&nbsp;     *            The dimensions to scale the rendered board to.
&nbsp;     */
&nbsp;    private void render(Board board, Graphics graphics, Dimension window) {
<b class="nc">&nbsp;        int cellW = window.width / board.getWidth();</b>
<b class="nc">&nbsp;        int cellH = window.height / board.getHeight();</b>
&nbsp;
<b class="nc">&nbsp;        graphics.setColor(BACKGROUND_COLOR);</b>
<b class="nc">&nbsp;        graphics.fillRect(0, 0, window.width, window.height);</b>
&nbsp;
<b class="nc">&nbsp;        for (int y = 0; y &lt; board.getHeight(); y++) {</b>
<b class="nc">&nbsp;            for (int x = 0; x &lt; board.getWidth(); x++) {</b>
<b class="nc">&nbsp;                int cellX = x * cellW;</b>
<b class="nc">&nbsp;                int cellY = y * cellH;</b>
<b class="nc">&nbsp;                Square square = board.squareAt(x, y);</b>
<b class="nc">&nbsp;                render(square, graphics, cellX, cellY, cellW, cellH);</b>
&nbsp;            }
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Renders a single square on the given graphics context on the specified
&nbsp;     * rectangle.
&nbsp;     *
&nbsp;     * @param square
&nbsp;     *            The square to render.
&nbsp;     * @param graphics
&nbsp;     *            The graphics context to draw on.
&nbsp;     * @param x
&nbsp;     *            The x position to start drawing.
&nbsp;     * @param y
&nbsp;     *            The y position to start drawing.
&nbsp;     * @param width
&nbsp;     *            The width of this square (in pixels.)
&nbsp;     * @param height
&nbsp;     *            The height of this square (in pixels.)
&nbsp;     */
&nbsp;    private void render(Square square, Graphics graphics, int x, int y, int width, int height) {
<b class="nc">&nbsp;        square.getSprite().draw(graphics, x, y, width, height);</b>
<b class="nc">&nbsp;        for (Unit unit : square.getOccupants()) {</b>
<b class="nc">&nbsp;            unit.getSprite().draw(graphics, x, y, width, height);</b>
<b class="nc">&nbsp;        }</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2024-05-05 10:29</div>
</div>
</body>
</html>
